package com.lemon.smartsafety.app;

import android.text.Html;
import android.widget.CompoundButton;

import com.lemon.smartsafety.entity.safe.company.CompanyBuildingCheckItemVo;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingIndexVo;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingItemCountVo;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingVo;
import com.lemon.smartsafety.result.fire.FireInspectionItem;
import com.lemon.smartsafety.utils.common.Convertor;
import com.lemon.smartsafety.utils.common.StringUtils;

/**
 * Created by Cooliean on 16/3/27.
 */
public class DataInfo {
    //无状态
    public final static String COMMON_TAG = "0";
    //正常
    public final static String GREEN_TAG  = "1";
    //不正常
    public final static String YELLOW_TAG = "3";
    //无法运行
    public final static String RED_TAG    = "2";

    public final static String GREEN_MARK  = "green_mark";
    public final static String YELLOW_MARK = "yellow_mark";
    public final static String RED_MARK    = "red_mark";


    //green_mark
    public static boolean canRepair(String markCode) {
        if (markCode.toLowerCase().equals("yellow_mark") || markCode.toLowerCase().equals("red_mark")) {
            return true;
        } else {
            return false;
        }
    }

    public static String getChinesePosition(String nPositionMark) {

        switch (Convertor.toInt(nPositionMark)) {
            case 1:
                return "西北";
            case 2:
                return "北";
            case 3:
                return "东北";
            case 4:
                return "西";
            case 5:
                return "中";
            case 6:
                return "东";
            case 7:
                return "西南";
            case 8:
                return "南";
            case 9:
                return "东南";
        }
        return "";
    }

    /**
     * 获取周期中文名称
     *
     * @param sUnitCode
     * @return
     */
    public static String getUnitName(String sUnitCode) {
        if ("minute".equals(sUnitCode)) {
            return "分钟";
        }
        if ("hour".equals(sUnitCode)) {
            return "小时";
        }
        if ("day".equals(sUnitCode)) {
            return "天";
        }
        if ("month".equals(sUnitCode)) {
            return "月";
        }
        if ("year".equals(sUnitCode)) {
            return "年";
        }

        return "";
    }

    public static String getPositionTitle(CompanyBuildingVo build, CompanyBuildingIndexVo indexVo, CompanyBuildingItemCountVo countVo) {
        String formatString = "%s-【%s楼%s】";
        return getPositionTitle(build, indexVo, countVo, formatString);
    }


    public static String getPositionTitle(CompanyBuildingVo build, CompanyBuildingIndexVo indexVo, CompanyBuildingItemCountVo countVo, CompanyBuildingCheckItemVo itemVo) {
        String formatString   = "%s-【%s楼%s】-%s";
        String sPositionTitle = DataInfo.getChinesePosition(countVo.getPositionMark());
        if (StringUtils.nullValue(countVo.getTitleId()).length() != 0) {
            sPositionTitle = countVo.getPositionTitle() + "(" + DataInfo.getChinesePosition(countVo.getPositionMark()) + ")";
        }
        String result = String.format(formatString, indexVo.getBuildingTitle(), indexVo.getCurrentFloorNumber(), sPositionTitle, itemVo.getObjectTitle());
        return result;
    }

    public static String getPositionTitle(CompanyBuildingVo build, CompanyBuildingIndexVo indexVo, CompanyBuildingItemCountVo countVo, FireInspectionItem fireInspectionItem) {
        String formatString   = "%s-【%s楼%s】-%s";
        String sPositionTitle = DataInfo.getChinesePosition(countVo.getPositionMark());
        if (StringUtils.nullValue(countVo.getTitleId()).length() != 0) {
            sPositionTitle = countVo.getPositionTitle() + "(" + DataInfo.getChinesePosition(countVo.getPositionMark()) + ")";
        }
        String result = String.format(formatString, indexVo.getBuildingTitle(), indexVo.getCurrentFloorNumber(), sPositionTitle, fireInspectionItem.getObjectTitle());
        return result;
    }


    public static String getPositionTitle(CompanyBuildingVo build, CompanyBuildingIndexVo indexVo, CompanyBuildingItemCountVo countVo, String formatString) {
        String sPositionTitle = DataInfo.getChinesePosition(countVo.getPositionMark());
        if (StringUtils.nullValue(countVo.getTitleId()).length() != 0) {
            sPositionTitle = countVo.getPositionTitle() + "(" + DataInfo.getChinesePosition(countVo.getPositionMark()) + ")";
        }
        String result = String.format(formatString, indexVo.getBuildingTitle(), indexVo.getCurrentFloorNumber(), sPositionTitle);
        return result;
    }


    public enum ColorStatus {
        STATUS_RED("#ff5722"), STATUS_YELLOW("#FE9600"), STATUS_GREEN("#009688"), STATUS_BLUE("#03A9F4"), STATUS_GRAY("#B6B6B6"),;
        private String colorString;

        public String getColorString() {
            return colorString;
        }

        public void setColorString(String colorString) {
            this.colorString = colorString;
        }

        private ColorStatus(String colorString) {
            this.colorString = colorString;
        }

    }

    /**
     * 这个方法已经移到StringUtils了
     *
     * @param string
     * @param status
     * @return
     */
    @Deprecated
    public static CharSequence getStatusString(String string, ColorStatus status) {
        return Html.fromHtml("<font color=" + status.getColorString() + ">" + string + "</font>");
    }


    public static String getCheckStatusString(CompoundButton compoundButton) {
        if (compoundButton.isChecked()) {
            return "1";
        }

        return "0";
    }
}
